﻿using MobilesStore.Domain.Abstract;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MobilesStore.Domain.Entities;

namespace MobilesStore.WebUI.Controllers
{
    public class NavController : Controller
    {
        IProductsRepository repository;

        public NavController(IProductsRepository repository)
        {
            this.repository = repository;
        }

        public PartialViewResult Menu(String category=null)
        {
            ViewBag.selectedCategory = category;
            IEnumerable<String> categories = repository.Products
                .Select(p => p.ProductCategory)
                .Distinct()
                .OrderBy(x => x);
            return PartialView(categories);
        }

        public PartialViewResult LatestProductsSmall(int c=5)
        {
            IEnumerable<Product> produts = repository.Products
                .OrderByDescending(p => p.ProductID)
                .Take(c);
            return PartialView(produts);
        }

        public PartialViewResult BestSellerProductsSmall(int c=5)
        {
            IEnumerable<Product> produts = repository.Products
                .OrderBy(p=>p.ProductPrice)
                .Take(c);
            return PartialView(produts);
        }

        public PartialViewResult FeaturedProducts(int c = 9)
        {
            IEnumerable<Product> produts = repository.Products
                .OrderByDescending(p => p.ProductPrice)
                .Take(c);
            return PartialView(produts);
        }

        public PartialViewResult LatestProducts(int c = 9)
        {
            IEnumerable<Product> produts = repository.Products
                .OrderByDescending(p => p.ProductID)
                .Take(c);
            return PartialView(produts);
        }

        public PartialViewResult BestSellerProducts(int c = 9)
        {
            IEnumerable<Product> produts = repository.Products
                .OrderBy(p => p.ProductPrice)
                .Take(c);
            return PartialView(produts);
        }

        public PartialViewResult SpecialProducts(int c = 9)
        {
            IEnumerable<Product> produts = repository.Products
                .OrderByDescending(p=>p.ProductPrice)
                .Take(c);
            return PartialView(produts);
        }
    }
}
